/*
  Copyright (c) 2010 smath-view project
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
  
  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
*/
package pl.smath.view.model;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;
/**
 * AbstractMultiView - MultiTerm view
 * 
 * @author Damian Rodziewicz
 *
 */
public abstract class AbstractMultiView extends View {
	protected final Vector<View> views = new Vector<View>();

	/**
	 * Constructor
	 * @param text
	 */
	protected AbstractMultiView(String text) {
		super(text);
	}

	/**
	 * add view
	 * @param view
	 */
	public void addView(View view) {
		views.add(view);
	}
	
	/**
	 * add views
	 * @param List<View>
	 */
	public void addViews(List<View> viewList){
		for (View view : viewList) {
			this.addView(view);
		}
	}
	
	/**
	 * get the list of views
	 * views are not copied, vector is.
	 * @return List<View>
	 */
	public Vector<View> getViews(){
		Vector<View>	copy = new Vector<View>();
		Iterator<View>	it = views.iterator();
		
		while(it.hasNext()){
			copy.add(it.next());
		}
		return copy;
	}
	
	/**
	 * @param font the font to set
	 */
	@Override
	public void setFont(String font) {
		if (font.indexOf("px")!=-1) {
			this.setFontHeight(new Double(font.substring(0, font.indexOf("px"))));
			this.font = font.substring(font.indexOf("px ")+3);
			this.minusSign.setFont(this.font, this.getFontHeight());

			for (View view : this.views) {
				view.setFont(font);
			}
			
			update();
		} else {
			this.setFontHeight(null);
			this.font = null;
		}
	}
}
